package com.chinasoft.DealAirOriginData;

import com.chinasoft.DealAirOriginData.api.HdfsApi;
import com.chinasoft.DealAirOriginData.mapper.AddAirDataMapper;
import com.chinasoft.DealAirOriginData.pojo.AirOriginData;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.InputStream;
import java.util.List;

public class DealHiveResult {
    public static void main(String[] args) throws Exception {
        // 根据 sqlMapConfig.xml 得到输入流
        final InputStream is = Resources.getResourceAsStream("sqlMapConfig.xml");
        // 获取 sqlSessionFactory 工厂对象
        final SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(is);
        //  获取 sqlSession 对象
        final SqlSession sqlSession = factory.openSession();

        //执行mapper里面的select语句
        //通过接口实现mybatis实体
        AddAirDataMapper airMapper = sqlSession.getMapper(AddAirDataMapper.class);
        List<AirOriginData> airList = new HdfsApi().getAirList();
        for (AirOriginData air : airList) {
            airMapper.insert(air);
            System.out.println(air);
        }

        //提交事务
        sqlSession.commit();

        // 关闭对象
        sqlSession.close();
    }
}
